// 用来生成分类相关模拟数据的
import { topCategory } from '@/api/constants'
import Mock from 'mockjs'

const images = [
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(1).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(2).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(3).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(4).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(5).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(6).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(7).png',
  'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/img/category%20(8).png'
]

const getHeadCategroy = () => {
  const topCategoryList = topCategory.map(item => {
    // Mock.mock() 传入一个对象，对象的值可以使用mockjs的规则语法

    // 生成10条二级分类数据
    const children = []
    for (let i = 0; i < 10; i++) {
      children.push(Mock.mock({
        id: '@id',
        name: '@ctitle(2,3)',

        picture: images[Mock.mock('@integer(0,7)')]
      }))
    }
    // 生成9个商品
    const goods = []
    for (let i = 0; i < 9; i++) {
      goods.push(Mock.mock({
        id: '@id',
        name: '@ctitle(18,24)',
        desc: '@ctitle(10,12)',
        price: '@float(100,200,2,2)',

        picture: images[Mock.mock('@integer(0,7)')]
      }))
    }
    // 顶级分类
    return Mock.mock({
      id: '@id',
      name: item,
      children,
      // 为了支撑左侧分类推荐商品，需要追加9个商品
      goods
    })
  })
  return {
    msg: '获取头部分类成功',
    result: topCategoryList
  }
}

export default {
  // key ===> 生成数据的函数
  headCategory: getHeadCategroy
}
